package com.pfizer.DB;

import static com.pfizer.DB.DBUtils.DBNAME;
import static com.pfizer.DB.DBUtils.TABLEHANDOUT;
import static com.pfizer.DB.DBUtils.TABLEMESSAGE;
import static com.pfizer.DB.DBUtils.TABLENEWS;
import static com.pfizer.DB.DBUtils.TABLEQUESTION;
import static com.pfizer.DB.DBUtils.TABLESURVEY;
import static com.pfizer.DB.DBUtils.TABLESURVEYRESULT;
import static com.pfizer.DB.DBUtils.TABLEUSERLOG;
import static com.pfizer.DB.DBUtils.TABLEVIDEO;
import static com.pfizer.Entity.Handout.HANDOUTCLASSSTRING;
import static com.pfizer.Entity.Handout.HANDOUTDLPICCNTSTRING;
import static com.pfizer.Entity.Handout.HANDOUTFESTRING;
import static com.pfizer.Entity.Handout.HANDOUTICONSTRING;
import static com.pfizer.Entity.Handout.HANDOUTIDSTRING;
import static com.pfizer.Entity.Handout.HANDOUTLUTIMESTRING;
import static com.pfizer.Entity.Handout.HANDOUTPICCNTSTRING;
import static com.pfizer.Entity.Handout.HANDOUTQNSTRING;
import static com.pfizer.Entity.Handout.HANDOUTSUBJSTRING;
import static com.pfizer.Entity.Handout.HANDOUTURLPATHSTRING;
import static com.pfizer.Entity.Question.ANSWERTYPESTRING;
import static com.pfizer.Entity.Question.MAXSELECTCNTSTRING;
import static com.pfizer.Entity.Question.MINSELECTCNTSTRING;
import static com.pfizer.Entity.Question.OPTIONCNTSTRING;
import static com.pfizer.Entity.Question.OPTIONSTRING;
import static com.pfizer.Entity.Question.QUESTIONIDSTRING;
import static com.pfizer.Entity.Question.QUESTIONNAIREIDSTRING;
import static com.pfizer.Entity.Question.QUESTIONNOSTRING;
import static com.pfizer.Entity.Question.QUESTIONSUBJSTRING;
import static com.pfizer.Entity.Survey.SURVEYBGTIMESTRING;
import static com.pfizer.Entity.Survey.SURVEYCLASSSTRING;
import static com.pfizer.Entity.Survey.SURVEYEDTIMESTRING;
import static com.pfizer.Entity.Survey.SURVEYIDSTRING;
import static com.pfizer.Entity.Survey.SURVEYLUTIMESTRING;
import static com.pfizer.Entity.Survey.SURVEYQNSTRING;
import static com.pfizer.Entity.Survey.SURVEYREMARKSTRING;
import static com.pfizer.Entity.Survey.SURVEYSUBJSTRING;
import static com.pfizer.Entity.SurveyResult.DIVISIONSSTRING;
import static com.pfizer.Entity.SurveyResult.DOCTORNAMESTRING;
import static com.pfizer.Entity.SurveyResult.HOSPITALSTRING;
import static com.pfizer.Entity.SurveyResult.SRIDSTRING;
import static com.pfizer.Entity.SurveyResult.SRQUESTIONNAIRESTRING;
import static com.pfizer.Entity.SurveyResult.SRSURVEYIDSTRING;
import static com.pfizer.Entity.SurveyResult.SURVEYRESULTCONTSTRING;
import static com.pfizer.Entity.SurveyResult.SURVEYRESULTFLAGSTRING;
import static com.pfizer.Entity.SurveyResult.SURVEYRESULTTIMESTRING;
import static com.pfizer.Entity.UserLog.USERLOGCASECODESTRING;
import static com.pfizer.Entity.UserLog.USERLOGCLASSSTRING;
import static com.pfizer.Entity.UserLog.USERLOGPARENTIDSTRING;
import static com.pfizer.Entity.UserLog.USERLOGTIMESTRING;
import static com.pfizer.Entity.UserLog.USERLOGTYPESTRING;
import static com.pfizer.Entity.UserLog.USERLOGUSERIDSTRING;
import static com.pfizer.Entity.pMessage.MSGCONTSTRING;
import static com.pfizer.Entity.pMessage.MSGFLAGSTRING;
import static com.pfizer.Entity.pMessage.MSGIDSTRING;
import static com.pfizer.Entity.pMessage.MSGRECEIVERIDSTRING;
import static com.pfizer.Entity.pNews.NEWSBGTIMESTRING;
import static com.pfizer.Entity.pNews.NEWSCONTSTRING;
import static com.pfizer.Entity.pNews.NEWSEDTIMESTRING;
import static com.pfizer.Entity.pNews.NEWSIDSTRING;
import static com.pfizer.Entity.pNews.NEWSSUBJSTRING;
import static com.pfizer.Entity.pNews.PUBLISHERSTRING;
import static com.pfizer.Entity.pVideo.VIDEOCLASSSTRING;
import static com.pfizer.Entity.pVideo.VIDEODESCSTRING;
import static com.pfizer.Entity.pVideo.VIDEOIDSTRING;
import static com.pfizer.Entity.pVideo.VIDEOLOCALFILESTRING;
import static com.pfizer.Entity.pVideo.VIDEOLOCALPICSTRING;
import static com.pfizer.Entity.pVideo.VIDEOLUTIMESTRING;
import static com.pfizer.Entity.pVideo.VIDEONAMESTRING;
import static com.pfizer.Entity.pVideo.VIDEONETFILESTRING;
import static com.pfizer.Entity.pVideo.VIDEOPICSTRING;
import static com.pfizer.Entity.pVideo.VIDEOQNSTRING;
import static com.pfizer.Entity.pVideo.VIDEOSOURCESTRING;
import static com.pfizer.Entity.pVideo.VIDEOTYPESTRING;
import static com.pfizer.Entity.pVideo.VIDEOUPDTIMESTRING;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.pfizer.Entity.DowningFileInfo;
import com.pfizer.Entity.Handout;
import com.pfizer.Entity.Question;
import com.pfizer.Entity.Survey;
import com.pfizer.Entity.SurveyResult;
import com.pfizer.Entity.UserInfo;
import com.pfizer.Entity.UserLog;
import com.pfizer.Entity.pMessage;
import com.pfizer.Entity.pNews;
import com.pfizer.Entity.pVideo;
import com.pfizer.Public.PublicFunc;
import com.pfizer.pfizerExpertForPad.pfizerApplication;

/**
 * DataHelper--<b>數據庫操作類<b>-- 該類封裝了本系統所有對數據庫操作的功能
 */
public class DataHelper {
	// 初始化系統變量
	DBUtils dbu;
	Context context;
	SQLiteDatabase db;
	pfizerApplication pApplication;

	/**
	 * DataHelper:構造函數
	 * 
	 * @param mcontext
	 */
	public DataHelper(Context mcontext) {
		context = mcontext;
		dbu = new DBUtils(mcontext, DBNAME, null, 1);
		db = dbu.getWritableDatabase();
		pApplication = (pfizerApplication) mcontext.getApplicationContext();
	}

	/**
	 * setLoopCount:設置循環次數
	 * 
	 * @param lpCount
	 */
	public void setLoopCount(long lpCount, long lpDateTime) {
		db.execSQL("update tblCount set lpCount=?,lpDateTime=? where id=1",
				new Object[] { lpCount, lpDateTime });
	}

	/**
	 * setLoopCount:設置循環次數
	 * 
	 * @param lpCount
	 */
	public void setLpDateTime() {
		Date dt = new Date();
		db.execSQL("update tblCount set lpDateTime=? where id=1",
				new Object[] { dt.getTime() });
	}

	/**
	 * getLoopCount:獲取循環次數
	 * 
	 * @param lpCount
	 */
	public long getLoopCount() {
		Cursor c = db.query("tblCount", new String[] { "lpCount" }, "id=1",
				null, null, null, null);
		c.moveToFirst();
		long l = c.getLong(0);
		c.close();
		return l;
	}

	/**
	 * getLoopCount:獲取循環次數
	 * 
	 * @param lpCount
	 */
	public long getLpDateTime() {
		Cursor c = db.query("tblCount", new String[] { "lpDateTime" }, "id=1",
				null, null, null, null);
		c.moveToFirst();
		long l = c.getLong(0);
		c.close();
		return l;
	}

	/***
	 * 获取所有存入数据库的用户
	 * 
	 * @return usersList
	 */
	public List<UserInfo> getUserList() {
		List<UserInfo> usersList = new ArrayList<UserInfo>();
		Cursor cursor = db.query(DBUtils.TABLEUSERS, null, null, null, null,
				null, null);
		cursor.moveToFirst();
		while (!cursor.isAfterLast()
				&& (cursor.getString(cursor
						.getColumnIndex(UserInfo.USERIDSTRING))) != null) {
			UserInfo user = new UserInfo();
			user.setUserID(cursor.getString(cursor
					.getColumnIndex(UserInfo.USERIDSTRING)));// 从数据库中取用户名
			user.setUserPsw(cursor.getString(cursor
					.getColumnIndex(UserInfo.USERPSWSTRING)));// 从数据库中取用户密码
			user.setUserName(cursor.getString(cursor
					.getColumnIndex(UserInfo.USERNAMESTRING)));
			user.setUserEmail(cursor.getString(cursor
					.getColumnIndex(UserInfo.USEREMAILSTRING)));
			user.setLoginTime(cursor.getString(cursor
					.getColumnIndex(UserInfo.LOGINTIMESTRING)));// 从数据库中取登陆时间
			user.setProveCode(cursor.getString(cursor
					.getColumnIndex(UserInfo.PROVECODESTRING)));// 获取ProveCode
			usersList.add(user);// 将取得的数据存入list
			cursor.moveToNext();
		}
		cursor.close();
		return usersList;
	}

	/****
	 * 根据UserId获取该用户
	 */
	public UserInfo getUserByUserId(String UserId) {
		Cursor cursor = db.query(DBUtils.TABLEUSERS, null,
				UserInfo.USERIDSTRING + "=" + "'" + UserId + "'", null, null,
				null, null);
		cursor.moveToFirst();
		UserInfo user = new UserInfo();
		user.setUserID(cursor.getString(cursor
				.getColumnIndex(UserInfo.USERIDSTRING)));// 从数据库中取用户名
		user.setUserPsw(cursor.getString(cursor
				.getColumnIndex(UserInfo.USERPSWSTRING)));// 从数据库中取用户密码
		user.setUserName(cursor.getString(cursor
				.getColumnIndex(UserInfo.USERNAMESTRING)));
		user.setUserEmail(cursor.getString(cursor
				.getColumnIndex(UserInfo.USEREMAILSTRING)));
		user.setLoginTime(cursor.getString(cursor
				.getColumnIndex(UserInfo.LOGINTIMESTRING)));// 从数据库中取登陆时间
		user.setProveCode(cursor.getString(cursor
				.getColumnIndex(UserInfo.PROVECODESTRING)));// 获取ProveCode
		cursor.close();
		return user;
	}

	/***
	 * 向数据库中添加已经认证后的user
	 * 
	 * @param user
	 * @return
	 */
	public Long SaveUserInfo(UserInfo user) {
		ContentValues cValues = new ContentValues();
		cValues.put(UserInfo.USERIDSTRING, user.getUserID());
		cValues.put(UserInfo.USERPSWSTRING, user.getUserPsw());
		cValues.put(UserInfo.LOGINTIMESTRING, user.getLoginTime());
		cValues.put(UserInfo.USERNAMESTRING, user.getUserName());
		cValues.put(UserInfo.USEREMAILSTRING, user.getUserEMail());
		cValues.put(UserInfo.PROVECODESTRING, user.getProveCode());
		Long rowId = db.insert(DBUtils.TABLEUSERS, null, cValues);
		// Log.e("SaveUserInfo", rowId + "");
		return rowId;
	}

	/***
	 * 更新user表
	 * 
	 * @param user
	 * @return
	 */

	public int UpdateUserInfo(UserInfo user) {
		ContentValues values = new ContentValues();
		values.put(UserInfo.USERIDSTRING, user.getUserID());
		values.put(UserInfo.USERPSWSTRING, user.getUserPsw());
		values.put(UserInfo.USERNAMESTRING, user.getUserName());
		values.put(UserInfo.USEREMAILSTRING, user.getUserEMail());
		values.put(UserInfo.LOGINTIMESTRING, user.getLoginTime());
		int id = db.update(DBUtils.TABLEUSERS, values, null, null);
		// Log.e("UpdateUserInfo", id + "");
		return id;
	}

	/***
	 * 获取最后一次登陆用户
	 * 
	 * @return user
	 */
	public UserInfo getLastLoginUser() {
		UserInfo user =null;
		Cursor cursor = db.query(DBUtils.TABLEUSERS, null, null, null, null,
				null, UserInfo.LOGINTIMESTRING + " DESC");
		cursor.moveToFirst();
		if (!cursor.isAfterLast()
				&& (cursor.getString(cursor
						.getColumnIndex(UserInfo.LOGINTIMESTRING))) != null) {
			user=new UserInfo();
			user.setUserID(cursor.getString(cursor
					.getColumnIndex(UserInfo.USERIDSTRING)));
			user.setUserPsw(cursor.getString(cursor
					.getColumnIndex(UserInfo.USERPSWSTRING)));
			user.setUserName(cursor.getString(cursor
					.getColumnIndex(UserInfo.USERNAMESTRING)));
			user.setUserEmail(cursor.getString(cursor
					.getColumnIndex(UserInfo.USEREMAILSTRING)));
			user.setLoginTime(cursor.getString(cursor
					.getColumnIndex(UserInfo.LOGINTIMESTRING)));
			user.setProveCode(cursor.getString(cursor
					.getColumnIndex(UserInfo.PROVECODESTRING)));// 获取ProveCode
		}
		cursor.close();
		return user;
	}

	/***
	 * 根据输入用户判断密码是否与数据库中存入的密码匹配
	 * 
	 * @param user
	 */
	public Boolean UserPswTest(UserInfo user) {
		Boolean isCorrect = false;
		Cursor cursor = db.query(DBUtils.TABLEUSERS, null,
				UserInfo.USERIDSTRING + "=" + "'" + user.getUserID() + "'",
				null, null, null, null);
		cursor.moveToFirst();
		if (cursor.getString(cursor.getColumnIndex(UserInfo.USERIDSTRING)) != null) {
			if (user.getUserPsw().equals(
					cursor.getString(cursor
							.getColumnIndex(UserInfo.USERPSWSTRING)))) {
				isCorrect = true;
			} else {
				isCorrect = false;
			}
		}
		cursor.close();
		return isCorrect;
	}

	/***
	 * 根据userid查询数据库中是否含有此用户
	 * 
	 * @param userId
	 */
	public Boolean HaveUserInfo(String userId) {
		Boolean b = false;
		Cursor cursor = db.query(DBUtils.TABLEUSERS, null,
				UserInfo.USERIDSTRING + "=" + "'" + userId + "'", null, null,
				null, null);// 查询满足条件的列表
		b = cursor.moveToFirst();
		// Log.e("HaveUserInfo", b.toString());
		cursor.close();
		return b;
	}

	/**
	 * getDownThreadDataLength：根據下載文件路徑獲取下載線程數據
	 * 
	 * @param path
	 * @return
	 */
	public Map<Integer, Integer> getDownThreadDataLength(String path) {
		Cursor cursor = db
				.rawQuery(
						"select threadid, downlength from tblFileDownlog where downpath=?",
						new String[] { path });
		Map<Integer, Integer> data = new HashMap<Integer, Integer>();
		while (cursor.moveToNext()) {
			data.put(cursor.getInt(0), cursor.getInt(1));
		}
		cursor.close();
		return data;
	}

	/**
	 * addDownLog：添加下載日誌
	 * 
	 * @param path
	 * @param downType
	 * @param parentID
	 * @return
	 */
	public void addDownLog(String path, int downType, long parentID,
			String localFile) {
		db.beginTransaction();
		try {

			db
					.execSQL(
							"insert into tblFileDownlog(downpath, threadid, downlength,downType,parentID,localFile) values(?,?,?,?,?,?)",
							new Object[] { path, 1, 0, downType, parentID,
									localFile });

			db
					.execSQL(
							"insert into tblFileDowning(downpath,  localFile) values(?,?)",
							new Object[] { path, localFile });

			db.setTransactionSuccessful();
		} finally {
			db.endTransaction();
		}
	}

	/**
	 * updateDownlog：更新下載日誌
	 * 
	 * @param path
	 * @param map
	 * @return
	 */
	public void updateDownlog(String path, Map<Integer, Integer> map) {
		db.beginTransaction();
		try {
			for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
				db
						.execSQL(
								"update tblFileDownlog set downlength=? where downpath=? and threadid=?",
								new Object[] { entry.getValue(), path,
										entry.getKey() });
			}
			db.setTransactionSuccessful();
		} finally {
			db.endTransaction();
		}
	}

	/**
	 * deleteDownlogByPath：刪除下載日誌
	 * 
	 * @param path
	 * @return
	 */
	public void deleteDownlogByPath(String path) {
		db.beginTransaction();
		try {
			Cursor cursor = db
					.rawQuery(
							"select downType,parentID,localFile from tblFileDownlog where downpath=?",
							new String[] { path });
			String localFile = "";
			int downType = 0;
			int parentID = 0;
			if (cursor.getCount() > 0) {
				cursor.moveToFirst();
				downType = cursor.getInt(0);
				parentID = cursor.getInt(1);
				localFile = cursor.getString(2);
			}
			cursor.close();
			switch (downType) {
			case 1:
				db.execSQL("update " + TABLEHANDOUT + " set "
						+ HANDOUTDLPICCNTSTRING + "=" + HANDOUTDLPICCNTSTRING
						+ "+1 where " + HANDOUTIDSTRING + "=?",
						new String[] { String.valueOf(parentID) });
				break;
			case 2:
				db.execSQL("update " + TABLEVIDEO + " set "
						+ VIDEOLOCALPICSTRING + "=? where " + VIDEOIDSTRING
						+ "=?", new String[] { localFile,
						String.valueOf(parentID) });
				break;
			case 3:
				db.execSQL("update " + TABLEVIDEO + " set "
						+ VIDEOLOCALFILESTRING + "=? where " + VIDEOIDSTRING
						+ "=?", new String[] { localFile,
						String.valueOf(parentID) });
				break;
			}

			db
					.execSQL(
							"insert into tblFileDowned(downpath,  localFile) values(?,?)",
							new Object[] { path, localFile });

			db.execSQL("delete from tblFileDownlog where downpath=?",
					new Object[] { path });
			db.execSQL("delete from tblFileDowning where downpath=?",
					new Object[] { path });

			db.setTransactionSuccessful();
		} finally {
			db.endTransaction();
		}
	}

	/**
	 * delDownlogByPath：刪除下載日誌
	 * 
	 * @param path
	 * @return
	 */
	public void delDownlogByPath(String path) {
		db.beginTransaction();
		try {
			db.execSQL("delete from tblFileDownlog where downpath=?",
					new Object[] { path });
			db.setTransactionSuccessful();
		} finally {
			db.endTransaction();
		}
	}

	/**
	 * clearDownlog：清空下載日誌
	 * 
	 * @return
	 */
	public void clearDownlog() {
		db.beginTransaction();
		try {
			db.execSQL("delete from tblFileDownlog");
			db.setTransactionSuccessful();
		} finally {
			db.endTransaction();
		}
	}

	/**
	 * addDowned：添加已經下載日誌
	 * 
	 * @param path
	 * @param localFile
	 * @return
	 */
	public void addDowned(String path, String localFile) {
		db.beginTransaction();
		try {
			db
					.execSQL(
							"insert into tblFileDowned(downpath,  localFile) values(?,?)",
							new Object[] { path, localFile });
			db.setTransactionSuccessful();
		} finally {
			db.endTransaction();
		}
	}

	/**
	 * IsDownedByUrl：判斷path是否已經下載
	 * 
	 * @param path
	 * @return
	 */
	public boolean IsDownedByUrl(String path) {
		Cursor c = db.query("tblFileDowned", new String[] { "downpath" },
				"downpath=?", new String[] { path }, null, null, null);
		boolean b = c.getCount() > 0 ? true : false;
		c.close();
		return b;
	}

	/**
	 * deleteDownedByPath：刪除已經下載日誌
	 * 
	 * @param path
	 * @return
	 */
	public void deleteDownedByPath(String path) {
		db.beginTransaction();
		try {
			db.execSQL("delete from tblFileDowned where localFile=?",
					new Object[] { path });
			db.setTransactionSuccessful();
		} finally {
			db.endTransaction();
		}
	}

	/**
	 * addDowning：添加正在下載日誌
	 * 
	 * @param path
	 * @param localFile
	 * @return
	 */
	public void addDowning(String path, int dowType, long parentID,
			String localFile) {
		db.beginTransaction();
		try {
			db
					.execSQL(
							"insert into tblFileDowning(downpath,dowType,parentID,  localFile) values(?,?,?,?)",
							new Object[] { path, dowType, parentID, localFile });
			db.setTransactionSuccessful();
		} finally {
			db.endTransaction();
		}
	}

	/**
	 * getNotFinishedDownFile：獲取未下載完成的文件
	 * 
	 * @return List<DowningFileInfo>
	 */
	public List<DowningFileInfo> getNotFinishedDownFile() {
		List<DowningFileInfo> lstDfInfos = new ArrayList<DowningFileInfo>();
		Cursor c = db.query("tblFileDownlog", new String[] { "downpath",
				"parentID", "downType", "localFile" },
				"downpath not in (select downpath from tblFileDowning)", null,
				"downpath,downType,parentID,localFile", null, null);
		while (c.moveToNext()) {
			DowningFileInfo dfInfo = new DowningFileInfo();
			dfInfo.setUrl(c.getString(0));
			dfInfo.setID(c.getLong(1));
			dfInfo.setType(c.getInt(2));
			dfInfo.setLocalPath(c.getString(3));
			lstDfInfos.add(dfInfo);
		}
		c.close();
		return lstDfInfos;
	}

	/**
	 * getDowningCount：獲取正在下載的文件數量
	 * 
	 * @return int
	 */
	public int getDowningCount() {
		Cursor c = db.rawQuery("select localFile from tblFileDowning", null);
		int i = c.getCount();
		c.close();
		return i;
	}

	/**
	 * IsDowningByUrl：判斷path是否正在下載
	 * 
	 * @param path
	 * @return boolean
	 */
	public boolean IsDowningByUrl(String path) {
		Cursor c = db.rawQuery(
				"select localFile from tblFileDowning where downpath=?",
				new String[] { path });
		int i = c.getCount();
		c.close();
		if (i > 0) {
			return true;
		} else {
			return false;
		}

	}

	/**
	 * deleteDowningByUrl：根据URL删除正在下載日志
	 * 
	 * @param path
	 */
	public void deleteDowningByUrl(String path) {
		db.beginTransaction();
		try {
			db.execSQL("delete from tblFileDowning where downpath=?",
					new Object[] { path });
			db.setTransactionSuccessful();
		} finally {
			db.endTransaction();
		}
	}

	/**
	 * deleteDowningByPath：根據本地path删除正在下載日志
	 * 
	 * @param path
	 */
	public void deleteDowningByPath(String path) {
		db.beginTransaction();
		try {
			db.execSQL("delete from tblFileDowning where localFile=?",
					new Object[] { path });
			db.setTransactionSuccessful();
		} finally {
			db.endTransaction();
		}
	}

	/**
	 * clearDowning：清空正在下載日志
	 * 
	 */
	public void clearDowning() {
		db.beginTransaction();
		try {
			db.execSQL("delete from tblFileDowning");
			db.setTransactionSuccessful();
		} finally {
			db.endTransaction();
		}
	}

	/**
	 * isExistsHandoutByID：根據ID判斷文章是否存在
	 * 
	 * @param _ID
	 * @return boolean
	 */
	public boolean isExistsHandoutByID(long _ID) {
		Cursor c = db.query(TABLEHANDOUT, new String[] { HANDOUTIDSTRING,
				HANDOUTLUTIMESTRING }, HANDOUTIDSTRING + "="
				+ String.valueOf(_ID), null, null, null, null);
		boolean b = c.getCount() > 0 ? true : false;
		c.close();
		return b;
	}

	/**
	 * isExistsHandoutByIDandTime：根據ID和最後更新時間判斷文章是否存在
	 * 
	 * @param _ID
	 * @param _lstTime
	 * @return boolean
	 */
	public boolean isExistsHandoutByIDandTime(long _ID, long _lstTime) {
		Cursor c = db.query(TABLEHANDOUT, new String[] { HANDOUTIDSTRING,
				HANDOUTLUTIMESTRING }, HANDOUTIDSTRING + "="
				+ String.valueOf(_ID) + " and " + HANDOUTLUTIMESTRING + "="
				+ String.valueOf(_lstTime), null, null, null, null);
		boolean b = c.getCount() > 0 ? true : false;
		c.close();
		return b;
	}

	/**
	 * getNeedDownPicHandoutList：取得需要下載圖片內容的文章列表
	 * 
	 * @return List<Handout>
	 */
	public List<Handout> getNeedDownPicHandoutList() {
		List<Handout> handouts = new ArrayList<Handout>();
		Cursor c = db.query(TABLEHANDOUT, new String[] { HANDOUTIDSTRING,
				HANDOUTICONSTRING, HANDOUTPICCNTSTRING, HANDOUTFESTRING,
				HANDOUTURLPATHSTRING }, HANDOUTPICCNTSTRING + "-"
				+ HANDOUTDLPICCNTSTRING + ">-1", null, null, null, null);
		while (c.moveToNext()) {
			Handout handout = new Handout();
			handout.setID(c.getLong(0));
			handout.setIcon(c.getString(1));
			handout.setPicCnt(c.getInt(2));
			handout.setFilenameExtension(c.getString(3));
			handout.setUrlPath(c.getString(4));
			handouts.add(handout);
		}
		c.close();
		return handouts;
	}

	/**
	 * getHandoutByID：根據ID獲取文章實體
	 * 
	 * @param _ID
	 * @return Handout
	 */
	public Handout getHandoutByID(String _ID) {

		Cursor c = db.query(TABLEHANDOUT, new String[] { HANDOUTIDSTRING,
				HANDOUTPICCNTSTRING, HANDOUTFESTRING, HANDOUTQNSTRING },
				HANDOUTIDSTRING + "=" + _ID, null, null, null,
				HANDOUTLUTIMESTRING + " DESC");
		Handout handout = null;
		if (c.getCount() > 0) {
			c.moveToFirst();
			handout = new Handout();
			handout.setID(c.getLong(0));
			handout.setDlPicCnt(c.getInt(1));
			handout.setFilenameExtension(c.getString(2));
			handout.setQuestionnaire(c.getLong(3));
		}
		c.close();
		return handout;
	}

	/**
	 * getHandoutListByClass：根據分類取得文章列表
	 * 
	 * @param _Class
	 * @return List<Handout>
	 */
	public List<Handout> getHandoutListByClass(String _Class) {
		List<Handout> handouts = new ArrayList<Handout>();
		Cursor c = db.query(TABLEHANDOUT, new String[] { HANDOUTIDSTRING,
				HANDOUTICONSTRING, HANDOUTSUBJSTRING, HANDOUTPICCNTSTRING,
				HANDOUTDLPICCNTSTRING, HANDOUTQNSTRING, HANDOUTFESTRING,
				HANDOUTLUTIMESTRING }, HANDOUTCLASSSTRING + " like '%" + _Class
				+ "%'", null, null, null, HANDOUTLUTIMESTRING + " DESC");
		while (c.moveToNext()) {
			Handout handout = new Handout();
			handout.setID(c.getLong(0));
			handout.setIcon(c.getString(1));
			handout.setSubj(c.getString(2));
			handout.setPicCnt(c.getInt(3));
			handout.setDlPicCnt(c.getInt(4));
			handout.setQuestionnaire(c.getLong(5));
			handout.setFilenameExtension(c.getString(6));
			handout.setLstUpdTime(c.getLong(7));
			handouts.add(handout);
		}
		c.close();
		return handouts;
	}

	/**
	 * getHandoutMapListByClass：根據分類取得文章MAP列表
	 * 
	 * @param localPath
	 * @param _Class
	 * @return List<Map<String, Object>>
	 */
	public List<Map<String, Object>> getHandoutMapListByClass(String localPath,
			String _Class) {
		List<Map<String, Object>> handouts = new ArrayList<Map<String, Object>>();
		/*
		 * Cursor c = db.query(TABLEHANDOUT, new String[] { HANDOUTIDSTRING,
		 * HANDOUTICONSTRING, HANDOUTSUBJSTRING, HANDOUTLUTIMESTRING },
		 * HANDOUTCLASSSTRING + " like '%" + _Class +
		 * "%' and "+HANDOUTPICCNTSTRING+"<"+HANDOUTDLPICCNTSTRING, null, null,
		 * null, HANDOUTLUTIMESTRING + " DESC");
		 */
		Cursor c = db.query(TABLEHANDOUT, new String[] { HANDOUTIDSTRING,
				HANDOUTICONSTRING, HANDOUTSUBJSTRING, HANDOUTLUTIMESTRING },
				HANDOUTCLASSSTRING + " like '%" + _Class + "%'", null, null,
				null, HANDOUTLUTIMESTRING + " DESC");
		while (c.moveToNext()) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("ID", String.valueOf(c.getLong(0)));
			map.put("Title", c.getString(2));
			map.put("Icon", String.format("%sHandout/%d/%s", localPath, c
					.getLong(0), c.getString(1)));
			Date dt = new Date(c.getLong(3) * 1000);
			map.put("LstUpdTime", DateFormat(dt));
			handouts.add(map);
		}
		c.close();
		return handouts;
	}

	/**
	 * addHandout：向數據庫添加新文章
	 * 
	 * @param _handout
	 * @return boolean
	 */
	public boolean addHandout(Handout _handout) {
		try {
			ContentValues cValues = new ContentValues();
			cValues.put(HANDOUTIDSTRING, _handout.getID());
			cValues.put(HANDOUTICONSTRING, _handout.getIcon());
			cValues.put(HANDOUTSUBJSTRING, _handout.getSubj());
			cValues.put(HANDOUTPICCNTSTRING, _handout.getPicCnt());
			cValues.put(HANDOUTDLPICCNTSTRING, _handout.getDlPicCnt());
			cValues.put(HANDOUTCLASSSTRING, _handout.getHandoutClass());
			cValues.put(HANDOUTFESTRING, _handout.getFilenameExtension());
			cValues.put(HANDOUTQNSTRING, _handout.getQuestionnaire());
			cValues.put(HANDOUTLUTIMESTRING, _handout.getLstUpdTime());
			cValues.put(HANDOUTURLPATHSTRING, _handout.getUrlPath());
			Long rowId = db.insert(TABLEHANDOUT, null, cValues);
			if (rowId > 0) {
				return true;
			} else {
				return false;
			}
		} catch (Exception ex) {
			return false;
		}
	}

	/**
	 * updateHandout：更新數據庫中的某文章
	 * 
	 * @param _handout
	 * @return boolean
	 */
	public boolean updateHandout(Handout _handout) {
		try {
			ContentValues cValues = new ContentValues();
			cValues.put(HANDOUTIDSTRING, _handout.getID());
			cValues.put(HANDOUTICONSTRING, _handout.getIcon());
			cValues.put(HANDOUTSUBJSTRING, _handout.getSubj());
			cValues.put(HANDOUTPICCNTSTRING, _handout.getPicCnt());
			cValues.put(HANDOUTDLPICCNTSTRING, _handout.getDlPicCnt());
			cValues.put(HANDOUTCLASSSTRING, _handout.getHandoutClass());
			cValues.put(HANDOUTFESTRING, _handout.getFilenameExtension());
			cValues.put(HANDOUTQNSTRING, _handout.getQuestionnaire());
			cValues.put(HANDOUTLUTIMESTRING, _handout.getLstUpdTime());
			cValues.put(HANDOUTURLPATHSTRING, _handout.getUrlPath());
			int count = db.update(TABLEHANDOUT, cValues,
					HANDOUTIDSTRING + "=?", new String[] { String
							.valueOf(_handout.getID()) });
			if (count == 1) {
				return true;
			} else {
				return false;
			}
		} catch (Exception ex) {
			return false;
		}
	}

	/**
	 * deleteHandoutNotIDS：刪除不在IDS範圍內的文章
	 * 
	 * @param _IDS
	 * @return boolean
	 */
	public boolean deleteHandoutNotIDS(long[] _IDS) {
		int ilength = _IDS.length;
		String sIds = "";
		for (int i = 0; i < ilength; i++) {
			sIds += String.format("%d,", _IDS[i]);
		}
		Cursor c = null;
		if (ilength > 0) {
			sIds = sIds.substring(0, sIds.length() - 1);
			c = db.query(TABLEHANDOUT, new String[] { HANDOUTIDSTRING,
					HANDOUTPICCNTSTRING, HANDOUTFESTRING }, HANDOUTIDSTRING
					+ " not in (" + sIds + ")", null, null, null, null);
		} else {
			c = db.query(TABLEHANDOUT, new String[] { HANDOUTIDSTRING,
					HANDOUTPICCNTSTRING, HANDOUTFESTRING }, null, null, null,
					null, null);
		}
		long iId = 0;
		String sPicPath = "";
		while (c.moveToNext()) {
			iId = c.getLong(0);

			sPicPath = String.format("%s/Handout/%d/", pApplication
					.getPfizerDir(), iId);
			PublicFunc.delFolder(sPicPath);
			//deleteDir(sPicPath);
		}
		c.close();
		if (ilength > 0) {
			db.delete(TABLEHANDOUT, HANDOUTIDSTRING + " not in (" + sIds + ")",
					null);
		} else {
			db.delete(TABLEHANDOUT, null, null);
		}
		return true;
	}

	/**
	 * deleteHandoutByID：根據ID刪除文章
	 * 
	 * @param _ID
	 * @return boolean
	 */
	public boolean deleteHandoutByID(long _ID) {
		String sPicPath = String.format("%s/Handout/%d/", pApplication
				.getPfizerDir(), _ID);
		Cursor c = db.query(TABLEHANDOUT, new String[] { HANDOUTIDSTRING,
				HANDOUTQNSTRING }, HANDOUTIDSTRING + "=" + String.valueOf(_ID),
				null, null, null, null);
		if (c.getCount() > 0) {
			c.moveToFirst();
			long qnID = c.getLong(1);
			db.delete(TABLEQUESTION, QUESTIONNAIREIDSTRING + "="
					+ String.valueOf(qnID), null);
		}
		deleteDir(sPicPath);
		db.delete(TABLEHANDOUT, HANDOUTIDSTRING + " =" + String.valueOf(_ID),
				null);
		c.close();
		return true;
	}

	/**
	 * isExistsVideoByID：根據ID判斷視頻是否存在
	 * 
	 * @param _ID
	 * @return boolean
	 */
	public boolean isExistsVideoByID(long _ID) {
		Cursor c = db.query(TABLEVIDEO, new String[] { VIDEOIDSTRING,
				VIDEOUPDTIMESTRING, VIDEOLUTIMESTRING }, VIDEOIDSTRING + "="
				+ String.valueOf(_ID), null, null, null, null);
		boolean b = c.getCount() > 0 ? true : false;
		c.close();
		return b;
	}

	/**
	 * isExistsVideoByID：根據ID和最後更新時間判斷視頻是否存在
	 * 
	 * @param _ID
	 * @param _lstTime
	 * @return boolean
	 */
	public boolean isExistsVideoByIDandTime(long _ID, long _lstTime) {
		Cursor c = db.query(TABLEVIDEO, new String[] { VIDEOIDSTRING,
				VIDEOUPDTIMESTRING, VIDEOLUTIMESTRING }, VIDEOIDSTRING + "="
				+ String.valueOf(_ID) + " and " + VIDEOLUTIMESTRING + "="
				+ String.valueOf(_lstTime), null, null, null, null);
		boolean b = c.getCount() > 0 ? true : false;
		c.close();
		return b;
	}

	public List<pVideo> getNeedDownPicVideoList() {
		List<pVideo> videos = new ArrayList<pVideo>();
		Cursor c = db.query(TABLEVIDEO, new String[] { VIDEOIDSTRING,
				VIDEOPICSTRING }, VIDEOLOCALPICSTRING + "=''", null, null,
				null, null);
		while (c.moveToNext()) {
			pVideo video = new pVideo();
			video.setID(c.getInt(0));
			video.setPic(c.getString(1));
			videos.add(video);
		}
		c.close();
		return videos;
	}

	/**
	 * getNeedDownFileVideoList：獲取需要下載視頻的視頻列表
	 * 
	 * @return List<pVideo>
	 */
	public List<pVideo> getNeedDownFileVideoList() {
		List<pVideo> videos = new ArrayList<pVideo>();
		Cursor c = db.query(TABLEVIDEO, new String[] { VIDEOIDSTRING,
				VIDEONETFILESTRING }, VIDEOLOCALFILESTRING + "=''", null, null,
				null, null);
		while (c.moveToNext()) {
			pVideo video = new pVideo();
			video.setID(c.getInt(0));
			video.setNetFile(c.getString(1));
			videos.add(video);
		}
		c.close();
		return videos;
	}

	/**
	 * getVideoByID：根據ID取得視頻實體
	 * 
	 * @param _ID
	 * @return pVideo
	 */
	public pVideo getVideoByID(String _ID) {
		pVideo video = null;
		Cursor c = db.query(TABLEVIDEO, new String[] { VIDEOIDSTRING,
				VIDEONAMESTRING, VIDEODESCSTRING, VIDEOLOCALFILESTRING },
				VIDEOIDSTRING + " = " + _ID, null, null, null, null);
		if (c.getCount() > 0) {
			c.moveToFirst();
			video = new pVideo();
			video.setID(c.getLong(0));
			video.setName(c.getString(1));
			video.setDesc(c.getString(2));
			video.setLocalFile(c.getString(3));
		}
		c.close();
		return video;
	}

	/**
	 * getVideoListByClassAndType：根據類型和類別取得視頻列表
	 * 
	 * @param _Class
	 * @param _Type
	 * @return List<pVideo>
	 */
	public List<pVideo> getVideoListByClassAndType(String _Class, int _Type) {
		List<pVideo> videos = new ArrayList<pVideo>();
		Cursor c = db.query(TABLEVIDEO, new String[] { VIDEOIDSTRING,
				VIDEONAMESTRING, VIDEODESCSTRING, VIDEOLOCALPICSTRING,
				VIDEOLOCALFILESTRING, VIDEOLUTIMESTRING }, VIDEOCLASSSTRING
				+ " like '%" + _Class + "%' and " + VIDEOTYPESTRING + "="
				+ String.valueOf(_Type), null, null, null, VIDEOLUTIMESTRING
				+ " DESC");
		while (c.moveToNext()) {
			pVideo video = new pVideo();
			video.setID(c.getLong(0));
			video.setName(c.getString(1));
			video.setDesc(c.getString(2));
			video.setLocalPic(c.getString(3));
			video.setLocalFile(c.getString(4));
			video.setLstUpdTime(c.getLong(5));
			videos.add(video);
		}
		c.close();
		return videos;
	}

	/**
	 * getVideoMapListByClassAndType：根據類型和類別取得視頻MAP列表
	 * 
	 * @param _Class
	 * @param _Type
	 * @return List<Map<String, Object>>
	 */
	public List<Map<String, Object>> getVideoMapListByClassAndType(
			String _Class, int _Type) {

		List<Map<String, Object>> videos = new ArrayList<Map<String, Object>>();
		/*
		 * Cursor c = db.query(TABLEVIDEO, new String[] { VIDEOIDSTRING,
		 * VIDEONAMESTRING, VIDEOLOCALPICSTRING, VIDEOLUTIMESTRING },
		 * VIDEOCLASSSTRING + " like '%" + _Class + "%' and " + VIDEOTYPESTRING
		 * + "=" + String.valueOf(_Type)+" and "+VIDEOLOCALFILESTRING+"<>''",
		 * null, null, null, VIDEOLUTIMESTRING + " DESC");
		 */
		Cursor c = db.query(TABLEVIDEO, new String[] { VIDEOIDSTRING,
				VIDEONAMESTRING, VIDEOLOCALPICSTRING, VIDEOLUTIMESTRING },
				VIDEOCLASSSTRING + " like '%" + _Class + "%' and "
						+ VIDEOTYPESTRING + "=" + String.valueOf(_Type), null,
				null, null, VIDEOLUTIMESTRING + " DESC");
		while (c.moveToNext()) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("ID", String.valueOf(c.getLong(0)));
			map.put("Title", c.getString(1));
			map.put("Icon", c.getString(2));
			Date dt = new Date(c.getLong(3) * 1000);
			map.put("LstUpdTime", DateFormat(dt));
			videos.add(map);
		}
		c.close();
		return videos;
	}

	/**
	 * addVideo：向數據庫添加新紀錄
	 * 
	 * @param _video
	 * @return boolean
	 */
	public boolean addVideo(pVideo _video) {
		try {
			if (_video.getLstUpdTime() == 0) {
				_video.setLstUpdTime(_video.getUpdTime());
			}
			ContentValues cValues = new ContentValues();
			cValues.put(VIDEOIDSTRING, _video.getID());
			cValues.put(VIDEONAMESTRING, _video.getName());
			cValues.put(VIDEOTYPESTRING, _video.getType());
			cValues.put(VIDEODESCSTRING, _video.getDesc());
			cValues.put(VIDEOSOURCESTRING, _video.getSource());
			cValues.put(VIDEONETFILESTRING, _video.getNetFile());
			cValues.put(VIDEOPICSTRING, _video.getPic());
			cValues.put(VIDEOUPDTIMESTRING, _video.getUpdTime());
			cValues.put(VIDEOCLASSSTRING, _video.getVideoClass());
			cValues.put(VIDEOQNSTRING, _video.getQuestionnaire());
			cValues.put(VIDEOLUTIMESTRING, _video.getLstUpdTime());
			cValues.put(VIDEOLOCALPICSTRING, "");
			cValues.put(VIDEOLOCALFILESTRING, "");
			Long rowId = db.insert(TABLEVIDEO, null, cValues);
			if (rowId > 0) {
				return true;
			} else {
				return false;
			}
		} catch (Exception ex) {
			return false;
		}
	}

	/**
	 * updateVideo：更新數據庫中某紀錄
	 * 
	 * @param _video
	 * @return boolean
	 */
	public boolean updateVideo(pVideo _video) {
		try {
			if (_video.getLstUpdTime() == 0) {
				_video.setLstUpdTime(_video.getUpdTime());
			}
			ContentValues cValues = new ContentValues();
			cValues.put(VIDEOIDSTRING, _video.getID());
			cValues.put(VIDEONAMESTRING, _video.getName());
			cValues.put(VIDEOTYPESTRING, _video.getType());
			cValues.put(VIDEODESCSTRING, _video.getDesc());
			cValues.put(VIDEOSOURCESTRING, _video.getSource());
			cValues.put(VIDEONETFILESTRING, _video.getNetFile());
			cValues.put(VIDEOPICSTRING, _video.getPic());
			cValues.put(VIDEOUPDTIMESTRING, _video.getUpdTime());
			cValues.put(VIDEOCLASSSTRING, _video.getVideoClass());
			cValues.put(VIDEOQNSTRING, _video.getQuestionnaire());
			cValues.put(VIDEOLUTIMESTRING, _video.getLstUpdTime());
			cValues.put(VIDEOLOCALPICSTRING, "");
			cValues.put(VIDEOLOCALFILESTRING, "");
			int count = db.update(TABLEVIDEO, cValues, VIDEOIDSTRING + "=?",
					new String[] { String.valueOf(_video.getID()) });
			if (count == 1) {
				return true;
			} else {
				return false;
			}
		} catch (Exception ex) {
			return false;
		}
	}

	public boolean clearVedioFile(long _ID) {
		ContentValues cValues = new ContentValues();
		cValues.put(VIDEOLOCALFILESTRING, "");
		int iRet = db.update(TABLEVIDEO, cValues, VIDEOIDSTRING + " ="
				+ String.valueOf(_ID), null);
		cValues.clear();
		return iRet == 1 ? true : false;
	}

	/**
	 * deleteVideoByID：根據ID刪除數據庫中某視頻
	 * 
	 * @param _ID
	 * @return boolean
	 */
	public boolean deleteVideoByID(long _ID) {

		Cursor c = db.query(TABLEVIDEO, new String[] { VIDEOIDSTRING,
				VIDEOLOCALPICSTRING, VIDEOLOCALFILESTRING }, VIDEOIDSTRING
				+ " =" + String.valueOf(_ID), null, null, null, null);

		while (c.moveToNext()) {
			PublicFunc.deleteFile(c.getString(1));
			PublicFunc.deleteFile(c.getString(2));
		}
		c.close();
		db.delete(TABLEVIDEO, VIDEOIDSTRING + " =" + String.valueOf(_ID), null);

		return true;
	}

	/**
	 * deleteVideoNotIDS：刪除不在IDS範圍內的視頻
	 * 
	 * @param _IDS
	 * @return boolean
	 */
	public boolean deleteVideoNotIDS(long[] _IDS) {
		int ilength = _IDS.length;
		String sIds = "";
		for (int i = 0; i < ilength; i++) {
			sIds += String.format("%d,", _IDS[i]);
		}
		Cursor c = null;
		if (ilength > 0) {
			sIds = sIds.substring(0, sIds.length() - 1);
			c = db.query(TABLEVIDEO, new String[] { VIDEOIDSTRING,
					VIDEOLOCALPICSTRING, VIDEOLOCALFILESTRING }, VIDEOIDSTRING
					+ " not in (" + sIds + ")", null, null, null, null);
		} else {
			c = db.query(TABLEVIDEO, new String[] { VIDEOIDSTRING,
					VIDEOLOCALPICSTRING, VIDEOLOCALFILESTRING }, null, null,
					null, null, null);
		}
		while (c.moveToNext()) {
			PublicFunc.deleteFile(c.getString(1));
			PublicFunc.deleteFile(c.getString(2));
		}
		c.close();
		if (ilength > 0) {
			db.delete(TABLEVIDEO, VIDEOIDSTRING + " not in (" + sIds + ")",
					null);
		} else {
			db.delete(TABLEVIDEO, null, null);
		}
		return true;
	}

	/**
	 * isExistsSurveyByID：根據ID判斷問卷調查是否存在
	 * 
	 * @param _ID
	 * @return boolean
	 */
	public boolean isExistsSurveyByID(long _ID) {
		Cursor c = db.query(TABLESURVEY, new String[] { SURVEYIDSTRING,
				SURVEYLUTIMESTRING }, SURVEYIDSTRING + "="
				+ String.valueOf(_ID), null, null, null, null);
		boolean b = c.getCount() > 0 ? true : false;
		c.close();
		return b;
	}

	/**
	 * isExistsSurveyByIDandTime：根據ID和最後更新時間判斷問卷調查是否存在
	 * 
	 * @param _ID
	 * @param _lstTime
	 * @return boolean
	 */
	public boolean isExistsSurveyByIDandTime(long _ID, long _lstTime) {
		Cursor c = db.query(TABLESURVEY, new String[] { SURVEYIDSTRING,
				SURVEYLUTIMESTRING }, SURVEYIDSTRING + "="
				+ String.valueOf(_ID) + " and " + SURVEYLUTIMESTRING + "="
				+ String.valueOf(_lstTime), null, null, null, null);
		boolean b = c.getCount() > 0 ? true : false;
		c.close();
		return b;
	}

	/**
	 * getSurveyMapList：獲取問卷調查Map列表
	 * 
	 * @return List<Map<String, Object>>
	 */
	public List<Map<String, Object>> getSurveyMapList() {
		List<Map<String, Object>> surveies = new ArrayList<Map<String, Object>>();
		Cursor c = db.query(TABLESURVEY, new String[] { SURVEYIDSTRING,
				SURVEYQNSTRING, SURVEYSUBJSTRING, SURVEYREMARKSTRING,
				SURVEYLUTIMESTRING }, null, null, null, null,
				SURVEYLUTIMESTRING + " DESC");
		while (c.moveToNext()) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("ID", String.valueOf(c.getLong(0)));
			map.put("qnID", String.valueOf(c.getLong(1)));
			map.put("Title", c.getString(2));
			map.put("Cont", c.getString(3));
			Date dt = new Date(c.getLong(4) * 1000);
			map.put("BgTime", DateFormat(dt));
			surveies.add(map);
		}
		c.close();
		return surveies;
	}

	/**
	 * getSurveyList：獲取問卷調查列表
	 * 
	 * @return List<Survey>
	 */
	public List<Survey> getSurveyList() {
		List<Survey> surveies = new ArrayList<Survey>();
		Cursor c = db.query(TABLESURVEY, new String[] { SURVEYIDSTRING,
				SURVEYSUBJSTRING, SURVEYBGTIMESTRING, SURVEYEDTIMESTRING,
				SURVEYREMARKSTRING, SURVEYQNSTRING, SURVEYLUTIMESTRING }, null,
				null, null, null, null);
		while (c.moveToNext()) {
			Survey survey = new Survey();
			survey.setID(c.getLong(0));
			survey.setSubject(c.getString(1));
			survey.setBgTime(c.getLong(2));
			survey.setEdTime(c.getLong(3));
			survey.setRemark(c.getString(4));
			survey.setQuestionnaire(c.getLong(5));
			survey.setLstUpdTime(c.getLong(6));
			surveies.add(survey);
		}
		c.close();
		return surveies;
	}

	/**
	 * addSurvey：向數據庫添加新紀錄
	 * 
	 * @param _survey
	 * @return boolean
	 */
	public boolean addSurvey(Survey _survey) {
		try {
			ContentValues cValues = new ContentValues();
			cValues.put(SURVEYIDSTRING, _survey.getID());
			cValues.put(SURVEYSUBJSTRING, _survey.getSubject());
			cValues.put(SURVEYBGTIMESTRING, _survey.getBgTime());
			cValues.put(SURVEYEDTIMESTRING, _survey.getEdTime());
			cValues.put(SURVEYREMARKSTRING, _survey.getRemark());
			cValues.put(SURVEYCLASSSTRING, _survey.getSurveyClass());
			cValues.put(SURVEYQNSTRING, _survey.getQuestionnaire());
			cValues.put(SURVEYLUTIMESTRING, _survey.getLstUpdTime());
			Long rowId = db.insert(TABLESURVEY, null, cValues);
			if (rowId > 0) {
				return true;
			} else {
				return false;
			}
		} catch (Exception ex) {
			return false;
		}
	}

	/**
	 * updateSurvey：更新數據庫中某問卷調查
	 * 
	 * @param _survey
	 * @return boolean
	 */
	public boolean updateSurvey(Survey _survey) {
		try {
			ContentValues cValues = new ContentValues();
			cValues.put(SURVEYIDSTRING, _survey.getID());
			cValues.put(SURVEYSUBJSTRING, _survey.getSubject());
			cValues.put(SURVEYBGTIMESTRING, _survey.getBgTime());
			cValues.put(SURVEYEDTIMESTRING, _survey.getEdTime());
			cValues.put(SURVEYREMARKSTRING, _survey.getRemark());
			cValues.put(SURVEYCLASSSTRING, _survey.getSurveyClass());
			cValues.put(SURVEYQNSTRING, _survey.getQuestionnaire());
			cValues.put(SURVEYLUTIMESTRING, _survey.getLstUpdTime());
			int count = db.update(TABLESURVEY, cValues, SURVEYIDSTRING + "=?",
					new String[] { String.valueOf(_survey.getID()) });
			if (count == 1) {
				return true;
			} else {
				return false;
			}
		} catch (Exception ex) {
			return false;
		}
	}

	/**
	 * deleteSurveyNotIDS：刪除不在IDS範圍內的問卷調查
	 * 
	 * @param _IDS
	 * @return boolean
	 */
	public boolean deleteSurveyNotIDS(long[] _IDS) {
		int ilength = _IDS.length;
		String sIds = "";
		for (int i = 0; i < ilength; i++) {
			sIds += String.format("%d,", _IDS[i]);
		}
		if (ilength > 0) {
			sIds = sIds.substring(0, sIds.length() - 1);
			db.delete(TABLESURVEY, SURVEYIDSTRING + " not in (" + sIds + ")",
					null);
		} else {
			db.delete(TABLESURVEY, null, null);
		}
		return true;
	}

	/**
	 * deleteSurveyByID：根據ID刪除問卷調查
	 * 
	 * @param _ID
	 * @return boolean
	 */
	public boolean deleteSurveyByID(long _ID) {

		Cursor c = db.query(TABLESURVEY, new String[] { SURVEYIDSTRING,
				SURVEYQNSTRING }, SURVEYIDSTRING + "=" + String.valueOf(_ID),
				null, null, null, null);
		if (c.getCount() > 0) {
			c.moveToFirst();
			int qnID = c.getInt(1);
			db.delete(TABLEQUESTION, QUESTIONNAIREIDSTRING + "="
					+ String.valueOf(qnID), null);
		}
		db
				.delete(TABLESURVEY,
						SURVEYIDSTRING + "=" + String.valueOf(_ID), null);
		c.close();
		return true;
	}

	/**
	 * isExistsQuestionByID：根據ID判斷試題是否存在
	 * 
	 * @param _ID
	 * @return boolean
	 */
	public boolean isExistsQuestionByID(long _ID) {
		Cursor c = db.query(TABLEQUESTION, new String[] {
				QUESTIONNAIREIDSTRING, QUESTIONIDSTRING }, QUESTIONIDSTRING
				+ "=" + String.valueOf(_ID), null, null, null, null);
		boolean b = c.getCount() > 0 ? true : false;
		c.close();
		return b;
	}

	/**
	 * getQuestionList：根據qnID取得試題列表
	 * 
	 * @param _qnID
	 * @return List<Question>
	 */
	public List<Question> getQuestionList(long _qnID) {
		List<Question> questions = new ArrayList<Question>();
		Cursor c = db.query(TABLEQUESTION, new String[] { QUESTIONIDSTRING,
				QUESTIONNOSTRING, QUESTIONSUBJSTRING, ANSWERTYPESTRING,
				OPTIONCNTSTRING, OPTIONSTRING, MINSELECTCNTSTRING,
				MAXSELECTCNTSTRING }, QUESTIONNAIREIDSTRING + "="
				+ String.valueOf(_qnID), null, null, null, QUESTIONNOSTRING
				+ " ASC");
		while (c.moveToNext()) {
			if (c.getString(3).equalsIgnoreCase("YesNo")
					|| c.getString(3).equalsIgnoreCase("Radio")) {
				Question question = new Question();
				question.setID(c.getLong(0));
				question.setNo(c.getInt(1));
				question.setSubj(c.getString(2));
				question.setAnswerType(c.getString(3));
				question.setOptionCnt(c.getInt(4));
				question.setOption(c.getString(5));
				question.setMaxSelectCnt(c.getInt(6));
				question.setMinSelectCnt(c.getInt(7));
				questions.add(question);
			}
		}
		c.close();
		return questions;
	}

	/**
	 * addQuestion：向數據庫添加新紀錄
	 * 
	 * @param _question
	 * @return boolean
	 */
	public boolean addQuestion(Question _question) {
		try {
			ContentValues cValues = new ContentValues();
			cValues.put(QUESTIONNAIREIDSTRING, _question.getQuestionnaireID());
			cValues.put(QUESTIONIDSTRING, _question.getID());
			cValues.put(QUESTIONNOSTRING, _question.getNo());
			cValues.put(QUESTIONSUBJSTRING, _question.getSubj());
			cValues.put(ANSWERTYPESTRING, _question.getAnswerType());
			cValues.put(OPTIONCNTSTRING, _question.getOptionCnt());
			cValues.put(MINSELECTCNTSTRING, _question.getMinSelectCnt());
			cValues.put(MAXSELECTCNTSTRING, _question.getMaxSelectCnt());
			cValues.put(OPTIONSTRING, _question.getOptionString());
			Long rowId = db.insert(TABLEQUESTION, null, cValues);
			if (rowId > 0) {
				return true;
			} else {
				return false;
			}
		} catch (Exception ex) {
			return false;
		}
	}

	/**
	 * addQuestion：向數據庫添加新紀錄
	 * 
	 * @param _question
	 * @return boolean
	 */
	public boolean updateQuestion(Question _question) {
		try {
			ContentValues cValues = new ContentValues();
			cValues.put(QUESTIONNAIREIDSTRING, _question.getQuestionnaireID());
			cValues.put(QUESTIONIDSTRING, _question.getID());
			cValues.put(QUESTIONNOSTRING, _question.getNo());
			cValues.put(QUESTIONSUBJSTRING, _question.getSubj());
			cValues.put(ANSWERTYPESTRING, _question.getAnswerType());
			cValues.put(OPTIONCNTSTRING, _question.getOptionCnt());
			cValues.put(MINSELECTCNTSTRING, _question.getMinSelectCnt());
			cValues.put(MAXSELECTCNTSTRING, _question.getMaxSelectCnt());
			cValues.put(OPTIONSTRING, _question.getOptionString());
			int count = db.update(TABLEQUESTION, cValues, QUESTIONIDSTRING
					+ "=?", new String[] { String.valueOf(_question.getID()) });
			if (count == 1) {
				return true;
			} else {
				return false;
			}
		} catch (Exception ex) {
			return false;
		}
	}

	/**
	 * isExistsMessageByMsgIDAndUserID：根據ID和UserID判斷訊息是否存在
	 * 
	 * @param _ID
	 * @param _UserID
	 * @return boolean
	 */
	public boolean isExistsMessageByMsgIDAndUserID(long _ID, String _UserID) {
		Cursor c = db.query(TABLEMESSAGE, new String[] { MSGIDSTRING },
				MSGIDSTRING + "=" + String.valueOf(_ID) + " and "
						+ MSGRECEIVERIDSTRING + "='" + _UserID + "'", null,
				null, null, null);
		boolean b = c.getCount() > 0 ? true : false;
		c.close();
		return b;
	}

	/**
	 * isNewMessageByUserID：根據UserID判斷是否有新訊息存在
	 * 
	 * @param _UserID
	 * @return boolean
	 */
	public boolean isNewMessageByUserID(String _UserID) {
		Cursor c = db.query(TABLEMESSAGE, new String[] { MSGIDSTRING,
				MSGCONTSTRING }, MSGFLAGSTRING + "=0 and "
				+ MSGRECEIVERIDSTRING + " ='" + _UserID + "'", null, null,
				null, MSGIDSTRING + " ASC");
		boolean bIsExists = c.getCount() > 0 ? true : false;
		c.close();
		return bIsExists;
	}

	/**
	 * getNeedCheckMsgIDByUserID：根據UserID獲取已經查看過的訊息ID字符串
	 * 
	 * @param _UserID
	 * @return boolean
	 */
	public String getNeedCheckMsgIDByUserID(String _UserID) {
		Cursor c = db
				.query(TABLEMESSAGE, new String[] { "_id", MSGIDSTRING },
						MSGFLAGSTRING + "=2 and " + MSGRECEIVERIDSTRING + " ='"
								+ _UserID + "'", null, null, null, MSGIDSTRING
								+ " ASC");
		String sRet = "";
		while (c.moveToNext()) {
			sRet += String.format("%d,", c.getLong(1));
		}
		c.close();
		if (sRet.length() > 0) {
			sRet = sRet.substring(0, sRet.length() - 1);
		}
		return sRet;
	}

	/**
	 * getMessageByUserID：根據UserID獲取未查看的訊息列表
	 * 
	 * @param _UserID
	 * @return List<pMessage>
	 */
	public List<pMessage> getMessageByUserID(String _UserID) {
		List<pMessage> pmsgs = new ArrayList<pMessage>();
		Cursor c = db.query(TABLEMESSAGE, new String[] { "_id", MSGIDSTRING,
				MSGCONTSTRING }, MSGFLAGSTRING + "=0 and "
				+ MSGRECEIVERIDSTRING + " ='" + _UserID + "'", null, null,
				null, MSGIDSTRING + " ASC");
		while (c.moveToNext()) {
			pMessage pmsg = new pMessage();
			pmsg.setAutoID(c.getLong(0));
			pmsg.setMsgID(c.getLong(1));
			pmsg.setCont(c.getString(2));
			pmsgs.add(pmsg);
		}
		c.close();
		return pmsgs;
	}

	/**
	 * addMessage：向數據庫添加新訊息
	 * 
	 * @param _message
	 * @return List<pMessage>
	 */
	public boolean addMessage(pMessage _message) {
		try {
			ContentValues cValues = new ContentValues();
			cValues.put(MSGIDSTRING, _message.getMsgID());
			cValues.put(MSGRECEIVERIDSTRING, _message.getUserID());
			cValues.put(MSGCONTSTRING, _message.getCont());
			cValues.put(MSGFLAGSTRING, _message.getFlag());
			Long rowId = db.insert(TABLEMESSAGE, null, cValues);
			if (rowId > 0) {
				return true;
			} else {
				return false;
			}
		} catch (Exception ex) {
			return false;
		}
	}

	/**
	 * updateMessageFlag：根據UserId更新訊息標誌位
	 * 
	 * @param UserID
	 * @param _Flag
	 * @return
	 */
	public void updateMessageFlag(String UserID, int _Flag) {
		try {
			db.execSQL("update " + TABLEMESSAGE + " set " + MSGFLAGSTRING
					+ "=? where " + MSGRECEIVERIDSTRING + "=?", new Object[] {
					_Flag, UserID });
		} catch (Exception ex) {
			return;
		}
	}

	/**
	 * updateMessageFlag：根據ID更新訊息標誌位
	 * 
	 * @param _ID
	 * @param _Flag
	 * @return
	 */
	public void updateMessageFlag(long _ID, int _Flag) {
		try {
			db.execSQL("update " + TABLEMESSAGE + " set " + MSGFLAGSTRING
					+ "=? where _id=?", new Object[] { _Flag, _ID });
		} catch (Exception ex) {
			return;
		}
	}

	/**
	 * deleteMessageByMsgIDAndUserID：根據ID和UserID刪除訊息
	 * 
	 * @param _ID
	 * @param _UserID
	 * @return
	 */
	public void deleteMessageByMsgIDAndUserID(long _ID, String _UserID) {

		db.delete(TABLEMESSAGE, MSGIDSTRING + "=" + String.valueOf(_ID)
				+ " and " + MSGRECEIVERIDSTRING + "='" + _UserID + "'", null);
	}

	/**
	 * deleteMessageByMsgIDAndUserID：根據UserID刪除不在IDS範圍內的訊息
	 * 
	 * @param _IDS
	 * @param _UserID
	 * @return boolean
	 */
	public boolean deleteMessageNotIDS(int[] _IDS, String _UserID) {
		int ilength = _IDS.length;
		String sIds = "";
		for (int i = 0; i < ilength; i++) {
			sIds += String.format("%d,", _IDS[i]);
		}
		if (ilength > 0) {
			db.delete(TABLEMESSAGE, MSGIDSTRING + " not in (" + sIds + ") and "
					+ MSGRECEIVERIDSTRING + "='" + _UserID + "'", null);
		} else {
			db.delete(TABLEMESSAGE, null, null);
		}
		return true;
	}

	/**
	 * isExistsNewsByID：根據ID判斷公告是否存在
	 * 
	 * @param _ID
	 * @return boolean
	 */
	public boolean isExistsNewsByID(long _ID) {
		Cursor c = db.query(TABLENEWS, new String[] { NEWSIDSTRING },
				NEWSIDSTRING + "=" + String.valueOf(_ID), null, null, null,
				null);
		boolean b = c.getCount() > 0 ? true : false;
		c.close();
		return b;
	}

	/**
	 *getNewsMapList ：獲取新聞Map列表
	 * 
	 * @return List<Map<String, Object>>
	 */
	public List<Map<String, Object>> getNewsMapList() {
		List<Map<String, Object>> newss = new ArrayList<Map<String, Object>>();
		Date dt = new Date();
		Cursor c = db
				.query(TABLENEWS, new String[] { NEWSIDSTRING, NEWSSUBJSTRING,
						PUBLISHERSTRING, NEWSBGTIMESTRING }, NEWSBGTIMESTRING
						+ "<=? and " + NEWSEDTIMESTRING + ">=?", new String[] {
						String.valueOf(dt.getTime() / 1000),
						String.valueOf(dt.getTime() / 1000) }, null, null, null);
		while (c.moveToNext()) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("ID", String.valueOf(c.getLong(0)));
			map.put("Title", c.getString(1));
			map.put("Publisher", c.getString(2));
			dt = new Date(c.getLong(3) * 1000);
			map.put("BgTime", DateFormat(dt));
			newss.add(map);
		}
		c.close();
		return newss;
	}

	/**
	 *getNewsByID ：獲取新聞列表
	 * @param _ID
	 * @return pNews
	 */
	public pNews getNewsByID(long _ID) {
		//Date dt = new Date();
		Cursor c = db.query(TABLENEWS, new String[] { NEWSIDSTRING,
				NEWSCONTSTRING},
				NEWSIDSTRING + "=?", new String[] { String.valueOf(_ID) },
				null, null, null);
		c.moveToFirst();
		pNews pnews = new pNews();
		pnews.setID(c.getLong(0));
		pnews.setCont(c.getString(1));
		c.close();
		return pnews;
	}

	/**
	 *getNewsList ：獲取新聞列表
	 * 
	 * @return List<pNews>
	 */
	public List<pNews> getNewsList() {
		List<pNews> pnewss = new ArrayList<pNews>();
		Date dt = new Date();
		Cursor c = db
				.query(TABLENEWS, new String[] { NEWSIDSTRING, NEWSSUBJSTRING,
						PUBLISHERSTRING, NEWSBGTIMESTRING }, NEWSBGTIMESTRING
						+ "<=? and " + NEWSEDTIMESTRING + ">=?", new String[] {
						String.valueOf(dt.getTime() / 1000),
						String.valueOf(dt.getTime() / 1000) }, null, null, null);
		while (c.moveToNext()) {
			pNews pnews = new pNews();
			pnews.setID(c.getLong(0));
			pnews.setSubj(c.getString(1));
			pnews.setPublisher(c.getString(2));
			pnews.setBgTime(c.getLong(3));
			pnewss.add(pnews);
		}
		c.close();
		return pnewss;
	}

	/**
	 * addNews：向數據庫添加一條新紀錄
	 * 
	 * @param _news
	 * @return boolean
	 */
	public boolean addNews(pNews _news) {
		try {
			ContentValues cValues = new ContentValues();
			cValues.put(NEWSIDSTRING, _news.getID());
			cValues.put(NEWSSUBJSTRING, _news.getSubj());
			cValues.put(PUBLISHERSTRING, _news.getPublisher());
			cValues.put(NEWSCONTSTRING, _news.getCont());
			cValues.put(NEWSBGTIMESTRING, _news.getBgTime());
			cValues.put(NEWSEDTIMESTRING, _news.getEdTime());
			Long rowId = db.insert(TABLENEWS, null, cValues);
			if (rowId > 0) {
				return true;
			} else {
				return false;
			}
		} catch (Exception ex) {
			return false;
		}
	}

	/**
	 * updateNews：更新數據庫中某紀錄
	 * 
	 * @param _news
	 * @return boolean
	 */
	public boolean updateNews(pNews _news) {
		try {
			ContentValues cValues = new ContentValues();
			cValues.put(NEWSIDSTRING, _news.getID());
			cValues.put(NEWSSUBJSTRING, _news.getSubj());
			cValues.put(NEWSCONTSTRING, _news.getCont());
			cValues.put(NEWSBGTIMESTRING, _news.getBgTime());
			cValues.put(NEWSEDTIMESTRING, _news.getEdTime());
			int count = db.update(TABLENEWS, cValues, NEWSIDSTRING + "=?",
					new String[] { String.valueOf(_news.getID()) });
			if (count == 1) {
				return true;
			} else {
				return false;
			}
		} catch (Exception ex) {
			return false;
		}
	}

	/**
	 * deleteNewsNotIDS：刪除不在IDS範圍內的新聞數據
	 * 
	 * @param _IDS
	 * @return boolean
	 */
	public boolean deleteNewsNotIDS(long[] _IDS) {
		int ilength = _IDS.length;
		String sIds = "";
		for (int i = 0; i < ilength; i++) {
			sIds += String.format("%d,", _IDS[i]);
		}
		if (ilength > 0) {
			sIds = sIds.substring(0, sIds.length() - 1);
			db.delete(TABLENEWS, NEWSIDSTRING + " not in (" + sIds + ")", null);
		} else {
			db.delete(TABLENEWS, null, null);
		}
		return true;
	}

	/**
	 * deleteNewsByID：根據ID刪除的新聞數據
	 * 
	 * @param _ID
	 * @return boolean
	 */
	public boolean deleteNewsByID(long _ID) {
		db.delete(TABLENEWS, NEWSIDSTRING + "=" + String.valueOf(_ID), null);
		return true;
	}

	/**
	 * getNeedSendSurveyResult：獲取需要反饋的問卷調查結果列表
	 * 
	 * @return List<SurveyResult>
	 */
	public List<SurveyResult> getNeedSendSurveyResult() {
		List<SurveyResult> sresults = new ArrayList<SurveyResult>();
		Cursor c = db.query(TABLESURVEYRESULT, new String[] { SRIDSTRING,
				DOCTORNAMESTRING, HOSPITALSTRING, DIVISIONSSTRING,
				SRSURVEYIDSTRING, SRQUESTIONNAIRESTRING,
				SURVEYRESULTCONTSTRING, SURVEYRESULTTIMESTRING },
				SURVEYRESULTFLAGSTRING + "=0", null, null, null, SRIDSTRING
						+ " ASC");
		while (c.moveToNext()) {
			SurveyResult sresult = new SurveyResult();
			sresult.setID(c.getLong(0));
			sresult.setDoctorName(c.getString(1));
			sresult.setOwnedHospitals(c.getString(2));
			sresult.setDivisions(c.getString(3));
			sresult.setSurveyID(c.getLong(4));
			sresult.setQuestionNaire(c.getLong(5));
			sresult.setSurveyResultCont(c.getString(6));
			sresult.setSurveyResultTime(c.getLong(7));
			sresults.add(sresult);
		}
		c.close();
		return sresults;
	}

	/**
	 * addSurveyResult：向數據庫中添加新的問卷調查反饋結果
	 * 
	 * @param _sResult
	 * @return boolean
	 */
	public boolean addSurveyResult(SurveyResult _sResult) {
		try {
			ContentValues cValues = new ContentValues();
			cValues.put(DOCTORNAMESTRING, _sResult.getDoctorName());
			cValues.put(HOSPITALSTRING, _sResult.getOwnedHospitals());
			cValues.put(DIVISIONSSTRING, _sResult.getDivisions());
			cValues.put(SRSURVEYIDSTRING, _sResult.getSurveyID());
			cValues.put(SRQUESTIONNAIRESTRING, _sResult.getQuestionNaire());
			cValues.put(SURVEYRESULTCONTSTRING, _sResult.getSurveyResultCont());
			cValues.put(SURVEYRESULTTIMESTRING, _sResult.getSurveyResultTime());
			cValues.put(SURVEYRESULTFLAGSTRING, 0);
			Long rowId = db.insert(TABLESURVEYRESULT, null, cValues);
			if (rowId > 0) {
				return true;
			} else {
				return false;
			}
		} catch (Exception ex) {
			return false;
		}
	}

	/**
	 * updateSurveyResultFlag：更新問卷調查反饋的標誌位
	 * 
	 * @param _ID
	 * @param _Flag
	 * @return
	 */
	public void updateSurveyResultFlag(long _ID, int _Flag) {
		try {
			db.execSQL("update " + TABLESURVEYRESULT + " set "
					+ SURVEYRESULTFLAGSTRING + "=? where " + SRIDSTRING + "=?",
					new Object[] { _Flag, _ID });
		} catch (Exception ex) {
			return;
		}
	}

	/**
	 * updateSurveyResultFlag：更新問卷調查反饋的標誌位
	 * 
	 * @param _ID
	 * @param _Flag
	 * @return
	 */
	public boolean addUserLog(UserLog _userLog) {
		try {
			ContentValues cValues = new ContentValues();
			cValues.put(USERLOGUSERIDSTRING, _userLog.getUserID());
			cValues.put(USERLOGCASECODESTRING, _userLog.getCaseCode());
			cValues.put(USERLOGCLASSSTRING, _userLog.getClassID());
			cValues.put(USERLOGTYPESTRING, _userLog.getTypeID());
			cValues.put(USERLOGPARENTIDSTRING, _userLog.getParentID());
			cValues.put(USERLOGTIMESTRING, _userLog.getTime());
			Long rowId = db.insert(TABLEUSERLOG, null, cValues);
			if (rowId > 0) {
				return true;
			} else {
				return false;
			}
		} catch (Exception ex) {
			return false;
		}
	}

	/**
	 * isHandtouTest：根據病例碼和qnID判斷是否需要顯示文章小測驗
	 * 
	 * @param _caseCode
	 * @param _QNID
	 * @return boolean
	 */
	public boolean isHandtouTest(String _caseCode, long _QNID) {
		Cursor c = db.query(TABLEUSERLOG, new String[] { USERLOGTIMESTRING },
				USERLOGCASECODESTRING + "=? and " + USERLOGTYPESTRING
						+ "=5 and " + USERLOGPARENTIDSTRING + "=?",
				new String[] { _caseCode, String.valueOf(_QNID) }, null, null, null);
		boolean bIsTest = c.getCount() > 0 ? true : false;
		c.close();
		return bIsTest;
	}

	/**
	 * deleteDir：根據路徑刪除文件
	 * 
	 * @param _Dir
	 */
	public void deleteDir(String _Dir) {
		File d = new File(_Dir);
		if (d.exists()) {
			d.delete();
		}
	}

	/**
	 * clearDB：清空數據庫
	 */
	public void clearDB() {
		db.delete(TABLEVIDEO, null, null);
		db.delete(TABLEHANDOUT, null, null);
		db.delete(TABLESURVEY, null, null);
		db.delete(TABLEQUESTION, null, null);
		db.delete(TABLEMESSAGE, null, null);
	}

	

	/**
	 * DateFormat：格式化日期
	 * 
	 * @param _dt
	 * @return String
	 */
	public String DateFormat(Date _dt) {
		return String.format("%d.%d.%d", _dt.getYear() + 1900,
				_dt.getMonth() + 1, _dt.getDate());
	}

	public void close() {
		// NOTE: openHelper must now be a member of CallDataHelper;
		// you currently have it as a local in your constructor
		if (db != null) {
			db.close();
			dbu.close();
		}
	}
}
